<template>
    <div class="structure-sidebar">
        <i></i>
        <button class="reset" type="button" @click="OnChanged">
            <img
                :src="state ? `/static/InertialNavigation/ic_zhankai.png` : `/static/InertialNavigation/ic_shouqi.png`">
            <span>结构认知</span>
        </button>
        <div class="list-view-container">
            <div class="list-view">
                <div v-for="[id, config] of StructureComponent.Default.Configs" :key="id">
                    <input type="radio" name="结构模块" :id="'结构模块' + id" :value="id"
                        v-model="StructureComponent.Default.Id.value" hidden>
                    <label :for="'结构模块' + config.Id" v-show="StructureComponent.Default.CanShowNode(id)">
                        <strong
                            :style="{marginLeft:`${StructureComponent.Default.CalculateIndent(id) * 3}rem`}"></strong>
                        <img v-show="StructureComponent.Default.HasChildren(id)"
                            :style="{transform:`rotateZ(${StructureComponent.Default.IsNodeExpand(id) ? 0 : 270}deg)`}"
                            src="/static/InertialNavigation/ic_arrow_down.png" alt="指示箭头"
                            @click.prevent="StructureComponent.Default.SwitchNodeExpand(id)">
                        <span>{{ config.Name }}</span>
                        <span></span>
                    </label>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { StructureComponent } from './InertialNavigationComponent';
import { reactive, ref } from 'vue';

const state = ref(true);
const sidebarTranslateX = ref('translateX(0)');
const buttonTranslateX = ref('translateX(0)');
function OnChanged() {
    state.value = !state.value;
    sidebarTranslateX.value = state.value ? 'translateX(0)' : 'translateX(100%)';
    buttonTranslateX.value = state.value ? 'translateX(0)' : 'translateX(-6rem)';
}
</script>

<style scoped>
::-webkit-scrollbar {
    width: 0.4rem;
    height: 0.4rem;
}

::-webkit-scrollbar-thumb {
    background: rgba(129, 133, 156, 0.3);
    border-radius: 0.2rem;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(129, 133, 156, 0.5);
}

::-webkit-scrollbar-track {
    border-radius: 0.2rem;
    background-color: rgba(129, 133, 156, 0.1);
}

.structure-sidebar {
    position: absolute;
    right: 0;
    top: 8rem;

    display: flex;
    flex-direction: column;
    justify-content: stretch;
    gap: 1rem;

    padding-bottom: 1rem;

    background-color: #131620;

    border-radius: 2rem 0 0 2rem;

    transform: v-bind(sidebarTranslateX);

    transition: transform 300ms;
}

.list-view-container {
    max-height: 54rem;
    overflow-y: overlay;
}

.list-view {
    /* display: flex; */
    flex-direction: column;
    justify-content: stretch;
    gap: 1rem;
}

button {
    width: 100%;
    height: 5rem;

    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1.4rem;

    padding-left: 2.4rem !important;
    padding-right: 2.4rem !important;

    background-color: #131620 !important;

    border-radius: 2.5rem 0 0 2.5rem;
    box-shadow: inset 0 -0.1rem 0 0 #1F1F2D;

    transform: v-bind(buttonTranslateX);

    transition: transform 300ms;

    cursor: pointer;
}

button>span:first-of-type {
    color: #B1B1D4;
    font-size: 1.8rem;
    font-weight: 500;
}

i {
    position: absolute;
    left: 0;
    bottom: 0;

    display: block;
    width: 100%;
    height: calc(100% - 6rem);

    border-left: solid 0.6rem transparent;
    border-bottom: solid 0.6rem transparent;
    border-radius: 0 0 0 2rem;
    background-image: linear-gradient(#131620, #131620),
        linear-gradient(90deg, #218cde, #807de1);
    background-origin: border-box;
    background-clip: content-box, border-box;

    z-index: -1;
}

label {
    width: 100%;
    height: 5.4rem;

    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;

    gap: 1rem;

    padding-left: 2rem;

    border-radius: 1rem;
}

label>span:first-of-type {
    flex-grow: 1;
}

label>span {
    color: #81859C;
    font-size: 1.6rem;
    font-weight: 500;

    white-space: nowrap;
}

input:checked+label>span {
    color: white;
    font-weight: 500;

    background: linear-gradient(90deg, #218CDE 0%, #807DE1 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

input:hover+label>span {
    color: white;
}

label>span:last-of-type {
    display: block;
    width: 0.4rem;
    height: 2rem;
}

input:checked+label>span:last-of-type {
    border-radius: 0.2rem;
    background: linear-gradient(180deg, #807DE1 0%, #218CDE 100%);
}
</style>